<template>
	<!--设备设置-->
	<j-modal :title="title" :width="width" :visible="visible" switchFullscreen @ok="handleOk"
		:okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
		:cancelButtonProps="{ class:{'jee-hidden': disableSubmit} }" @cancel="handleCancel" cancelText="关闭" okText="保存">
		<!--表单-->
		<a-spin :spinning="confirmLoading">
			<j-form-container class="scroll-view" style="height: 640px">
				<a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
					<a-row>
						<a-col :span="24">
							<a-table :columns="columns" :dataSource="scoreList" :pagination="ipagination" :loading="loading" bordered rowKey="id"
								style="margin: 0 auto;width: 100%;" @change="handleTableChange">
								<template slot="score" slot-scope="text, record">
									<span>{{(record.plusminusType === '1' &&  record.score != 0)?'+':(record.plusminusType === '2' && record.score != 0)?'-':''}}{{record.score}}</span>
								</template>
							</a-table>
						</a-col>
					</a-row>
				</a-form-model>
			</j-form-container>
		</a-spin>
	</j-modal>
</template>
<script>
	import {
		httpAction,
		getAction,
		postAction
	} from '@/api/manage'
	import { filterObj } from '@/utils/util';
	export default {
		name: 'WtDevicetypeModal',
		components: {

		},
		data() {
			return {
				title: '',
				width: 800,
				visible: false,
				disableSubmit: false,
				disabled: true,
				//表单
				confirmLoading: false,
				labelCol: {
					xs: {
						span: 24
					},
					sm: {
						span: 5
					}
				},
				wrapperCol: {
					xs: {
						span: 24
					},
					sm: {
						span: 16
					}
				},
				labelCol2: {
					xs: {
						span: 24
					},
					sm: {
						span: 2
					}
				},
				wrapperCol2: {
					xs: {
						span: 24
					},
					sm: {
						span: 22
					}
				},
				validatorRules: {},
				model: {},
				params: {
					rateeId: '',
					rateeType: '',
					latestScore: '',
					content: '',
					valuatorType: '',
				},
				pageType: '', //supplieredit-供应商评分编辑 supplierdetail-供应商评分列表 
				url: {
					add: '',
					edit: '',
					list: '',
					detail: '/score/wtScoreRecordDetail/queryList',
					delete: '',
				},
				columns: [{
						title: '评分时间',
						dataIndex: 'createTime',
						key: 'createTime',
						align: 'center',
						width: '25%',
					}, {
						title: '最后评分',
						dataIndex: 'latestScore',
						key: 'latestScore',
						align: 'center',
						width: '15%',
					},
					{
						title: '加减分',
						dataIndex: 'score',
						key: 'score',
						align: 'center',
						width: '15%',
						scopedSlots: {
							customRender: 'score'
						},
					},
					{
						title: '分类内容',
						dataIndex: 'scoreConfigurationeName',
						key: 'scoreConfigurationeName',
						align: 'center',
						width: '15%',
					},
					{
						title: '评价内容',
						dataIndex: 'content',
						key: 'content',
						align: 'center',
						width: '30%',
					}
				],
				scoreList: [],
				ipagination:{
					current: 1,
					pageSize: 10,
					pageSizeOptions: ['10', '20', '30'],
					showTotal: (total, range) => {
					  return range[0] + "-" + range[1] + " 共" + total + "条"
					},
					showQuickJumper: true,
					showSizeChanger: true,
					total: 0
				},
				/* 排序参数 */
				isorter:{
				  column: 'createTime',
				  order: 'desc',
				},
				/* 筛选参数 */
				filters: {},
				/* table加载状态 */
				loading:false,
			}
		},
		methods: {
			//下拉选择
			handleChange(type, item, index) {
				console.log(1, type, item, index);
				let _self = this;
			},
			//获取数据字典列表
			getDetail(arg) {
				var _self = this;
				//加载数据 若传入参数1则加载第一页的内容
				if (arg === 1) {
					this.ipagination.current = 1;
				}
				var params = this.getQueryParams();//查询条件
				params.scoreRecordId = this.model.id;
				this.loading = true;
				//运维评分记录
				getAction(`/score/wtScoreRecordDetail/list`,params).then((res) => {
					if (res.success) {
						//update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
						this.scoreList = res.result.records || res.result;
						if (res.result.total) {
							this.ipagination.total = res.result.total;
						} else {
							this.ipagination.total = 0;
						}
						this.$forceUpdate();
						//update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
					} else {
						this.$message.warning(res.message)
					}
				}).finally(() => {
					this.loading = false
				})
			},
			getQueryParams() {
			  //获取查询条件
			  let sqp = {}
			  if(this.superQueryParams){
			    sqp['superQueryParams']=encodeURI(this.superQueryParams)
			    sqp['superQueryMatchType'] = this.superQueryMatchType
			  }
			  
			  if(!!this.is_localstorage){
			    let localName = this.is_localstorage;
			    let queryParam = JSON.parse(localStorage.getItem(localName));
			    if(!!queryParam){
			      this.queryParam = queryParam;
			    }
			  }
			  var param = Object.assign(sqp, this.queryParam, this.isorter ,this.filters);
			  param.field = this.getQueryField();
			  param.pageNo = this.ipagination.current;
			  param.pageSize = this.ipagination.pageSize;
			  return filterObj(param);
			},
			getQueryField() {
			  //TODO 字段权限控制
			  var str = "id,";
			  if(this.columns && this.columns.length>0){
			    this.columns.forEach(function (value) {
			      str += "," + value.dataIndex;
			    });
			  }
			  return str;
			},
			//分页
			handleTableChange(pagination, filters, sorter) {
			  //分页、排序、筛选变化时触发
			  //TODO 筛选
			  console.log(pagination)
			  if (Object.keys(sorter).length > 0) {
			    this.isorter.column = sorter.field;
			    this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
			  }
			  this.ipagination = pagination;
			  this.getDetail();
			},
			add() {
				this.visible = true;
			},
			edit(record) {
				console.log(11, record)
				this.visible = true;
				this.model = record;
				this.getDetail();
			},
			close() {
				this.$emit('close');
				this.visible = false;
			},
			init() {
				this.params = {
					rateeId: '',
					rateeType: '',
					latestScore: '',
					content: '',
					valuatorType: '',
				}
			},
			handleOk() {
				const _self = this;
				let params = this.params;
				let httpurl = '';
				if (_self.pageType === 'supplieredit') {
					httpurl = _self.url.add;
					params.rateeId = _self.model.id;
					params.rateeType = '1';
					params.valuatorType = '1';
				} else if (_self.pageType === 'teamedit') {
					httpurl = _self.url.add;
					params.rateeId = _self.model.id;
					params.rateeType = '4';
					params.valuatorType = '1';
				}
				// 触发表单验证
				_self.confirmLoading = true;
				console.log('提交表单', params)
				// debugger
				httpAction(httpurl, params, 'POST')
					.then((res) => {
						if (res.success) {
							_self.$message.success(res.message);
							_self.close();
							_self.init();
							_self.$emit('ok');
						} else {
							_self.$message.warning(res.message)
						}
					})
					.finally(() => {
						_self.confirmLoading = false
					})
			},
			submitCallback() {
				this.$emit('ok');
				this.visible = false;
			},
			handleCancel() {
				this.close()
			}
		}
	}
</script>
<style scoped>
	.scroll-view {
		overflow: auto;
		overflow-y: scroll;
	}
</style>